#!/usr/bin/env python

import editor, json, sys

with open(sys.argv[1]) as f:
  lib = json.load(f)

if not 'config' in lib: lib['config'] = {}
if not 'preferences' in lib['config']: lib['config']['preferences'] = {}
if not 'postscript' in lib['config']['preferences']: lib['config']['preferences']['postscript'] = ''

lib['config']['preferences']['postscript'] = editor.edit(contents=lib['config']['preferences']['postscript']).decode('utf-8')

with open(sys.argv[1], 'w') as f:
  json.dump(lib, f, indent='  ')
